/** @jsxImportSource @emotion/react */
import {CCell,Table, TableBody, TableHead, TableRow, Text} from "customize-easy-ui-component";
import * as React from "react";
import {RepLink} from "../../common/base";

export const tail测量设= <Text css={{"@media print": {fontSize: '0.75rem'}}}>
  备注：性能状态一栏中用“√”表示正常，用“×”表示不正常，未使用的测量设备可不填写。
</Text>;
//1、主要测量设备性能检查 默认：第一次检验的仪表是 ?.仪器表; 复检仪器表是 ?.复检仪器
/**带上复检仪器 + 双排布局；
 * */
export const MeasInstrumentRe = ({orc, rep, label,}: { orc: any, rep: any, label: string }
) => {
  const instruments = React.useMemo(() => {
      const all设备名 = new Set([...(orc?.仪器表?.map((row: { n: any; }) => row.n)??[]), ...(orc?.复检仪器?.map((row: { n: any; }) => row.n)??[])]);
      //all设备名.forEach(a值 => {
      //   const row1 = orc?.仪器表.find(row => row.a === a值);
      //   const row2 = orc?.复检仪器.find(row => row.a === a值);
      //   let mergedRow = { ...(row1 || {}) };
      //   Object.assign(mergedRow, ...(Object.keys(row2 || {}).filter(key => key !== 'a' && (row1 ? !(key in row1) : true)).map(key => ({ [key]: row2[key] }))));
      //   合并表.push(mergedRow);
      // });
      const 合并仪表 = [...Array.from(all设备名).map((na: string) => ({
        n: na,
        l: (orc?.仪器表?.find((row: { n: string; }) => row.n === na) || {}),
        r: (orc?.复检仪器?.find((row: { n: string; }) => row.n === na) || {})
      }))];
      return 合并仪表;
  }, [orc?.仪器表, orc?.复检仪器]);
  return <>
    <div css={{"@media print": {pageBreakBefore: 'always',}}}>
      <Text id='MaxSpeed' variant="h4">{label}</Text>
    </div>
    <Table fixed={ ["%", "18.5%", "10%", "5.3%", "5.3%", "18.5%", "10%", "5.3%", "5.3%"] }
                css={{borderCollapse: 'collapse'}} tight miniw={800}>
      <TableHead>
        <TableRow>
          <RepLink ori rep={rep} tag={'Instrument'}>
            <CCell rowSpan={3}>测量设备名称</CCell>
            <CCell colSpan={4}>首次检验</CCell>
          </RepLink>
          <RepLink ori rep={rep} tag={'InstrumentReisp'}>
            <CCell colSpan={4}>复检</CCell>
          </RepLink>
        </TableRow>
        <TableRow>
          <RepLink ori rep={rep} tag={'Instrument'}>
            <CCell rowSpan={2}>规格型号</CCell><CCell rowSpan={2}>测量设备编号</CCell><CCell colSpan={2}>性能状态</CCell>
          </RepLink>
          <RepLink ori rep={rep} tag={'InstrumentReisp'}>
            <CCell rowSpan={2}>规格型号</CCell><CCell rowSpan={2}>测量设备编号</CCell><CCell colSpan={2}>性能状态</CCell>
          </RepLink>
        </TableRow>
        <TableRow>
          <CCell><Text css={{fontSize:'0.75rem'}}>开机后</Text></CCell><CCell><Text css={{fontSize:'0.75rem'}}>关机前</Text></CCell>
          <CCell><Text css={{fontSize:'0.75rem'}}>开机后</Text></CCell><CCell><Text css={{fontSize:'0.75rem'}}>关机前</Text></CCell>
        </TableRow>
      </TableHead>
      <TableBody>
        {instruments?.map((o: any, i: React.Key) => {
            return (
              <TableRow key={i}>
                  <RepLink ori rep={rep} tag={'Instrument'}>
                    <CCell>{o.n}</CCell>
                    <CCell>{o.l.t}</CCell>
                    <CCell css={{wordBreak: 'break-all'}}>{o.l.i}</CCell>
                    <CCell>{o.l.o}</CCell>
                    <CCell>{o.l.f}</CCell>
                  </RepLink>
                  <RepLink ori rep={rep} tag={'InstrumentReisp'}>
                    <CCell>{o.r.t}</CCell>
                    <CCell css={{wordBreak: 'break-all'}}>{o.r.i}</CCell>
                    <CCell>{o.r.o}</CCell>
                    <CCell>{o.r.f}</CCell>
                  </RepLink>
              </TableRow>
            );
        })}
      </TableBody>
    </Table>
    {tail测量设}
  </>;
};
